/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.yxw.yxnet_cd_center.customer_service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.common.constant.MqttPrefixConstant;
import com.yxw.yxnet_cd_center.customer_service.entity.YxcscClientFiledServiceEntity;
import com.yxw.yxnet_cd_center.customer_service.utils.ErrorLog;
import cn.hutool.core.util.ObjectUtil;
import com.yxw.yxnet_cd_center.customer_service.dto.YxcscFlockTalkRecordDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.SendDelayNoticeDTO;
import com.yxw.yxnet_cd_center.customer_service.mqtt.MqttGateway;
import org.springframework.beans.factory.annotation.Autowired;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttObjectSystemVO;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttInforSystemVO;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttTextInforFlockVO;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttObjectInforFlockVO;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttInforCustomerVO;
import com.yxw.yxnet_cd_center.customer_service.vo.SenderVO;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttSystemEventContenVO;
import com.yxw.yxnet_cd_center.common.enums.ContentTypeEnum;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsFlockUserEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsUserEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsUserWorkEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxcscBaseChannelUserEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.TechFlockUserEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.FlowRuleUserEntity;
import com.yxw.yxnet_cd_center.customer_service.mapper.YxcscBaseChannelUserMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.CustomerFlockUserMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.TechFlockUserMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.FlowRuleUserMapper;
import com.yxw.yxnet_cd_center.customer_service.service.UserWorkService;

import java.util.List;
import java.util.ArrayList;
import org.springframework.stereotype.Service;
import com.yxw.yxnet_cd_center.common.enums.NoticeTypeEnum;

import com.yxw.yxnet_cd_center.customer_service.service.ICacheService;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsNoticeEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsWorkflowEntity;
import com.yxw.yxnet_cd_center.customer_service.service.IMsgProcessService;

import com.yxw.yxnet_cd_center.customer_service.dto.SendNoticeViewDTO;


import com.yxw.yxnet_cd_center.customer_service.entity.CustomerFlockUserEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxcscServiceTalkRecordEntity;
import com.yxw.yxnet_cd_center.common.exception.BaseException;
import com.yxw.yxnet_cd_center.customer_service.entity.YxcscFlockTalkRecordEntity;
import com.yxw.yxnet_cd_center.customer_service.vo.MemberVo;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttSystemEventVO;
/**
import com.yxw.customer_service_center.customer_service.mapper.YxCsFlockUserMapper;
import com.yxw.customer_service_center.customer_service.mapper.UserMapper; 
import com.yxw.customer_service_center.customer_service.mapper.NoticeWayMapper; 
import com.yxw.customer_service_center.customer_service.service.impl.NoticeServiceImpl; 
import com.yxw.yxnet_cd_center.common.exception.BaseException;
import com.yxw.customer_service_center.customer_service.entity.NoticeWayEntity; 
import com.yxw.customer_service_center.customer_service.mapper.ChannelMapper;
import com.yxw.customer_service_center.customer_service.mapper.GroupMapper;
import com.yxw.customer_service_center.customer_service.mapper.FlockMapper;
import com.yxw.customer_service_center.customer_service.entity.YxCsChannelEntity;
import com.yxw.customer_service_center.customer_service.entity.YxCsGroupEntity;
import com.yxw.customer_service_center.customer_service.entity.YxCsFlockEntity;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import com.yxw.customer_service_center.customer_service.service.impl.MqttObjectServiceImpl;
* 
* 
 */




/**
 * 会话所有消息处理
 * @author hjx
 * @date 2023.09.22
 */
@Service
public class MsgProcessServiceImpl implements IMsgProcessService{
    
    @Autowired
    private MqttGateway oMqttGateway;
    
    //@Autowired
    //private YxCsFlockUserMapper oYxCsFlockUserMapper;
    
    //@Autowired
    //private MqttObjectServiceImpl oMqttObjectService;
    
    //@Autowired
    //private YxcscBaseChannelUserMapper oYxcscBaseChannelUserMapper;
    
    @Autowired
    private TechFlockUserMapper oTechFlockUserMapper;
    
    //@Autowired
    //private NoticeWayMapper oNoticeWayMapper;
    
    @Autowired
    private UserWorkService oUserWorkService;
    
    @Autowired
    private ICacheService oICacheService;
    
    @Autowired
    private NoticeServiceImpl oNoticeServiceImpl;
    
    @Autowired
    private CustomerFlockUserMapper oCustomerFlockUserMapper;
    
    //@Autowired
    //private FlowRuleUserMapper oFlowRuleUserMapper;
    
    //@Autowired
    //private UserMapper oUserMapper;
    /*** 
    * 客户申请服务后
    * @param oYxcscClientFiledServiceDTO
    * @return BaseResult
    **/  
    @Override
    public BaseResult sendSystemMsgByClientFiled(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,List<MemberVo> list)
    {
        String topic;        
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.COME_TO_VISIT);
        if(list.isEmpty())
        {
            ErrorLog.Log("sessionId:" +oYxcscClientFiledServiceEntity.getId() + "渠道 Name:" + oYxcscClientFiledServiceEntity.getChannelName() + "Code:" + oYxcscClientFiledServiceEntity.getChannelCode() + "没有配置分流参数和基础分流参数");
            //System.out.println("基础分流没有配置");
            throw new BaseException("没有配置分流参数和基础分流参数");        
        }
        for(MemberVo oMemberVo : list)
        {
            //发送客户申请相关的客服，客户申请，客服队列
            JSONObject oJSONObject = getMqttSystemEventJson(oYxcscClientFiledServiceEntity, "clientFiledService", oMemberVo, oYxCsNoticeEntity.getNoticeDec());
            topic = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(oMemberVo.getId().toString());
            oMqttGateway.sendToMqtt(topic, oJSONObject.toString());  
            ErrorLog.Log("客户申请服务后,发送客户申请相关的客服:" + oMemberVo.getUserName() + "Id:" + oMemberVo.getId());
            ErrorLog.Log("topic:" + topic);
            ErrorLog.Log("JSONObject:" + oJSONObject.toString());
            //System.out.println("完成系统消息----------------------------------------------------------------------------------------------------------------------------");
            //System.out.println("topic:" + topic);
            //System.out.print("JSONObject:");
            //System.out.print(oJSONObject.toString());
        }        
        if(null == oYxCsNoticeEntity)
        {
            //System.out.println("WORKFLOW_STATE_CHANGE 找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException("WORKFLOW_STATE_CHANGE  找不到通知配置参数,系统通知发送失败");
            ErrorLog.Log(NoticeTypeEnum.COME_TO_VISIT.getTemplateName() + "_COME_TO_VISIT_"+NoticeTypeEnum.COME_TO_VISIT.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            BaseResult.failed(NoticeTypeEnum.COME_TO_VISIT.getTemplateName() + "_COME_TO_VISIT_"+NoticeTypeEnum.COME_TO_VISIT.getCodeType()+"找不到通知配置参数,系统通知发送失败");
        }
        //通知
        SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
        oSendNoticeViewDTO.setBussId(oYxcscClientFiledServiceEntity.getId());
        oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
        oSendNoticeViewDTO.setContentType("text");
        oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
        oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
        oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
        oSendNoticeViewDTO.setUserList(list);
        oSendNoticeViewDTO.setType(NoticeTypeEnum.COME_TO_VISIT);
        oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO);
        JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
        ErrorLog.Log("发送通知完成:" + oJSONObjectxx.toString());
        //发送3分钟无处理延时消息
        if(oYxCsNoticeEntity.getStatus() == 1)
        {
            String topicInner = MqttPrefixConstant.THREE_POINTS_UNTREATED_TOPIC_PRODUCT;
            SendDelayNoticeDTO oSendDelayNoticeDTO = new SendDelayNoticeDTO();
            oSendDelayNoticeDTO.setBussId(oYxcscClientFiledServiceEntity.getId());
            oSendDelayNoticeDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendDelayNoticeDTO.setContentType("text");
            oSendDelayNoticeDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendDelayNoticeDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendDelayNoticeDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendDelayNoticeDTO.setUserList(list);
            oSendDelayNoticeDTO.setType(NoticeTypeEnum.COME_TO_VISIT);
            JSONObject oJSONObject = (JSONObject)JSON.toJSON(oSendDelayNoticeDTO);
            oMqttGateway.sendToMqtt(topicInner, oJSONObject.toString());
            ErrorLog.Log("发送3分钟无处理延时消息完成:" + oJSONObject.toString());
        }
        return BaseResult.success(list);
    }
    /*** 
    * 客服邀请客户对本次服务评分接口
    * @param userId  用户Id
    * @param sessionId  服务Id
    * @return BaseResult
    **/
    @Override
    public BaseResult customerInviteClientScore(YxCsUserEntity oYxCsUserEntity,YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity)
    {
        String topic = MqttPrefixConstant.SYSTEM_CLIENT_MQTT_TOPIC_PREFIX.concat(oYxcscClientFiledServiceEntity.getId());
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("msgType", "sys");
        oJSONObject.put("systemEventType", "inviteClientScore");
        oJSONObject.put("content", "inviteClientScore");
        oJSONObject.put("contentType", "text");
        oJSONObject.put("sessionId", oYxcscClientFiledServiceEntity.getId());
        JSONObject oSenderJSONObject = new JSONObject();
        oSenderJSONObject.put("userId", "system");
        oJSONObject.put("send", oSenderJSONObject);
        oJSONObject.put("recv", oYxcscClientFiledServiceEntity.getClientId());
        oJSONObject.put("sendTime",System.currentTimeMillis());
        oMqttGateway.sendToMqtt(topic, oJSONObject.toString());
        ErrorLog.Log("客服邀请客户对本次服务评分消息通知----------------------------------------------------------------------------------------------------------------------------");
        ErrorLog.Log("topic:" + topic);
        ErrorLog.Log("JSONObject:" + oJSONObject.toString());
        //System.out.println("客服邀请客户对本次服务评分消息通知----------------------------------------------------------------------------------------------------------------------------");
        //System.out.println("topic:" + topic);
        //System.out.print("JSONObject:");
        //System.out.print(oJSONObject.toString());                     
        return BaseResult.success();
    }
    /*** 
    * 客户发送聊天记录给客服
    * @param sendTalkMsgByClient
    * @return BaseResult
    **/
    @Override
    public BaseResult sendTalkMsgByClient(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,YxCsUserEntity oYxCsUserEntity,YxcscServiceTalkRecordEntity oYxcscServiceTalkRecordEntity)
    {
        String topic = MqttPrefixConstant.SYSTEM_USER_MQTT_TOPIC_PREFIX.concat(oYxcscClientFiledServiceEntity.getCoustId().toString());
        /*
        MqttInforCustomerVO oMqttInforCustomerVO = new MqttInforCustomerVO();
        oMqttInforCustomerVO.setRecordId(oYxcscServiceTalkRecordEntity.getId());
        oMqttInforCustomerVO.setSessionId(oYxcscServiceTalkRecordEntity.getSessionId());
        oMqttInforCustomerVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
        oMqttInforCustomerVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
        oMqttInforCustomerVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
        oMqttInforCustomerVO.setContent(oYxcscServiceTalkRecordEntity.getTalkInfo());
        oMqttInforCustomerVO.setContentType(oYxcscServiceTalkRecordEntity.getTalkInfoType());
        oMqttInforCustomerVO.setRecv(oYxcscClientFiledServiceEntity.getCoustId().toString());
        oMqttInforCustomerVO.setSendTime(oYxcscServiceTalkRecordEntity.getCreateTime());
        SenderVO oSenderVO = new SenderVO();
        oSenderVO.setUserId(oYxcscClientFiledServiceEntity.getClientId());
        oSenderVO.setNickName(oYxcscClientFiledServiceEntity.getClientName());
        oSenderVO.setAvatar(oYxcscClientFiledServiceEntity.getCoustAvatar());
        oMqttInforCustomerVO.setSender(oSenderVO);
        JSONObject oJSONObject = (JSONObject)JSON.toJSON(oMqttInforCustomerVO);
        */
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("recordId",oYxcscServiceTalkRecordEntity.getId());
        oJSONObject.put("sessionId",oYxcscServiceTalkRecordEntity.getSessionId());
        oJSONObject.put("channelCode",oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("portCode",oYxcscClientFiledServiceEntity.getPortCode());
        oJSONObject.put("shopId",oYxcscClientFiledServiceEntity.getShopId());
        oJSONObject.put("content",oYxcscServiceTalkRecordEntity.getTalkInfo());
        oJSONObject.put("contentType",oYxcscServiceTalkRecordEntity.getTalkInfoType());
        oJSONObject.put("recv",oYxcscClientFiledServiceEntity.getCoustId());
        oJSONObject.put("sendTime",oYxcscServiceTalkRecordEntity.getCreateTime());
        JSONObject oSenderJSONObject = new JSONObject();
        oSenderJSONObject.put("userId",oYxcscClientFiledServiceEntity.getClientId());
        oSenderJSONObject.put("nickName",oYxcscClientFiledServiceEntity.getClientName());
        oSenderJSONObject.put("avatar",oYxcscClientFiledServiceEntity.getCoustAvatar());
        oJSONObject.put("sender", oSenderJSONObject);
        oMqttGateway.sendToMqtt(topic, oJSONObject.toString());
        /*
        System.out.println("客户发送聊天记录给客服后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------聊天记录Id:" + oYxcscServiceTalkRecordEntity.getId());
        System.out.println("topic:" + topic);
        System.out.println("消息:");
        System.out.print(oJSONObject.toString());
        */
        ErrorLog.Log("客户发送聊天记录给客服后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------聊天记录Id:" + oYxcscServiceTalkRecordEntity.getId());
        ErrorLog.Log("topic:" + topic);
        ErrorLog.Log("JSONObject:" + oJSONObject.toString());        
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.MESSAGE_REPLY);
        if(null == oYxCsNoticeEntity)
        {
            //System.out.println("WORKFLOW_STATE_CHANGE 找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException("WORKFLOW_STATE_CHANGE  找不到通知配置参数,系统通知发送失败");
            System.out.println(NoticeTypeEnum.MESSAGE_REPLY.getTemplateName() + "_MESSAGE_REPLY_"+NoticeTypeEnum.MESSAGE_REPLY.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            ErrorLog.Log("客户发送聊天记录给客服:" + NoticeTypeEnum.MESSAGE_REPLY.getTemplateName() + "_MESSAGE_REPLY_"+NoticeTypeEnum.MESSAGE_REPLY.getCodeType()+"找不到通知配置参数,系统通知发送失败,TalkRecordId:" + oYxcscServiceTalkRecordEntity.getId());  
            return BaseResult.failed(NoticeTypeEnum.MESSAGE_REPLY.getTemplateName() + "_MESSAGE_REPLY_"+NoticeTypeEnum.MESSAGE_REPLY.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            //throw new BaseException(NoticeTypeEnum.MESSAGE_REPLY.getTemplateName() + "_MESSAGE_REPLY_"+NoticeTypeEnum.MESSAGE_REPLY.getCodeType()+"找不到通知配置参数,系统通知发送失败");            
        }
        List<MemberVo> list = new ArrayList();
        MemberVo oMemberVo = new MemberVo();
        oMemberVo.setId(oYxCsUserEntity.getUserId());
        oMemberVo.setUserName(oYxCsUserEntity.getUserName());
        oMemberVo.setPhone(oYxCsUserEntity.getMobilePhone());
        list.add(oMemberVo);
        
        if(oYxCsNoticeEntity.getStatus() == 1)
        {
            //发送通知
            SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
            oSendNoticeViewDTO.setBussId(oYxcscServiceTalkRecordEntity.getId().toString());
            oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendNoticeViewDTO.setContentType("text");
            oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendNoticeViewDTO.setUserList(list);
            oSendNoticeViewDTO.setType(NoticeTypeEnum.MESSAGE_REPLY);
            oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO);
            //System.out.println("客户发送聊天记录给客服后完成   发送通知----------------------------------------------------------------------------------------------------------------------------" + oYxcscServiceTalkRecordEntity.getId());
            ErrorLog.Log("客户发送聊天记录给客服后完成   发送通知----------------------------------------------------------------------------------------------------------------------------" + oYxcscServiceTalkRecordEntity.getId());
            JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
            ErrorLog.Log("发送通知完成:" + oJSONObjectxx.toString());            
            //发送3分钟无处理延时消息
            String topicFlock = MqttPrefixConstant.THREE_POINTS_UNTREATED_TOPIC_PRODUCT;
            SendDelayNoticeDTO oSendDelayNoticeDTO = new SendDelayNoticeDTO();
            oSendDelayNoticeDTO.setBussId(oYxcscServiceTalkRecordEntity.getId().toString());
            oSendDelayNoticeDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendDelayNoticeDTO.setContentType("text");
            oSendDelayNoticeDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendDelayNoticeDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendDelayNoticeDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendDelayNoticeDTO.setUserList(list);
            oSendDelayNoticeDTO.setType(NoticeTypeEnum.MESSAGE_REPLY);
            JSONObject oDelayNoticeJSONObject = (JSONObject)JSON.toJSON(oSendDelayNoticeDTO);
            oMqttGateway.sendToMqtt(topicFlock, oDelayNoticeJSONObject.toString());
            //System.out.println("客户发送聊天记录给客服后完成   发送3分钟无处理延时消息----------------------------------------------------------------------------------------------------------------------------" + oYxcscServiceTalkRecordEntity.getId());
            ErrorLog.Log("客户发送聊天记录给客服后完成   发送3分钟无处理延时消息----------------------------------------------------------------------------------------------------------------------------" + oYxcscServiceTalkRecordEntity.getId());            
            ErrorLog.Log("发送通知完成:" + oDelayNoticeJSONObject.toString());   
        }
        return BaseResult.success();
    }
    /*** 
    * 客服发送聊天记录给客户
    * @param sendTalkMsgByClient
    * @return BaseResult
    **/
    @Override
    public BaseResult sendTalkMsgByCustomer(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,YxcscServiceTalkRecordEntity oYxcscServiceTalkRecordEntity)
    {
        String topic = MqttPrefixConstant.SYSTEM_CLIENT_MQTT_TOPIC_PREFIX.concat(oYxcscClientFiledServiceEntity.getId());
        MqttInforCustomerVO oMqttInforCustomerVO = new MqttInforCustomerVO();
        SenderVO oSenderVO = new SenderVO();
        oSenderVO.setUserId(oYxcscClientFiledServiceEntity.getCoustId().toString());
        oSenderVO.setNickName(oYxcscClientFiledServiceEntity.getCoustName());        
        oMqttInforCustomerVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
        oMqttInforCustomerVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
        oMqttInforCustomerVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
        oMqttInforCustomerVO.setSender(oSenderVO);
        oMqttInforCustomerVO.setContent(oYxcscServiceTalkRecordEntity.getTalkInfo());
        oMqttInforCustomerVO.setContentType(oYxcscServiceTalkRecordEntity.getTalkInfoType());
        oMqttInforCustomerVO.setRecv(oYxcscClientFiledServiceEntity.getClientId());
        JSONObject oJSONObject = (JSONObject)JSON.toJSON(oMqttInforCustomerVO);
        oMqttGateway.sendToMqtt(topic, oJSONObject.toString());  
        ErrorLog.Log("客服发送聊天记录给客户后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------" + oYxcscServiceTalkRecordEntity.getId());
        ErrorLog.Log("topic:" + topic);
        ErrorLog.Log("JSONObject:" + oJSONObject.toString());   
        //System.out.println("客服发送聊天记录给客户后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------");
        //System.out.println("topic:" + topic);
        //System.out.print("oJSONObject:" + oJSONObject.toString());
        return BaseResult.success();
    }    
    /*** 
    * 客服发送群聊天信息到群
    * @param flockId
    * @param UserId
    * @param nickName
    * @param message
    * @param sendTime
    * @return BaseResult
    **/
    @Override
    public BaseResult sendFlockTalkMsgByCustomer(YxcscFlockTalkRecordEntity oYxcscFlockTalkRecordEntity)
    {
        //YxcscFlockTalkRecordDTO oYxcscFlockTalkRecordDTO,Long sendTime,Long msgId
        //String flockId,String UserId,String nickName,String message
        String topicFlock;
        //List<YxCsFlockUserEntity> oListYxCsFlockUserEntity = null;
        List<CustomerFlockUserEntity> oListCustomerFlockUserEntity = null;
        if(oYxcscFlockTalkRecordEntity.getFlockType() == 0)
        {
            topicFlock = MqttPrefixConstant.SYSTEM_FLOCK_MQTT_TOPIC_PREFIX.concat(oYxcscFlockTalkRecordEntity.getFlockId().toString());
            QueryWrapper<CustomerFlockUserEntity> oYxCsFlockUserQueryWrapper = new QueryWrapper();
            oYxCsFlockUserQueryWrapper.eq("flock_id",oYxcscFlockTalkRecordEntity.getFlockId()).orderByAsc("flock_id");
            oListCustomerFlockUserEntity = oCustomerFlockUserMapper.selectList(oYxCsFlockUserQueryWrapper);  
        }
        else
        {
            topicFlock = MqttPrefixConstant.SYSTEM_TECHFLOCK_MQTT_TOPIC_PREFIX.concat(oYxcscFlockTalkRecordEntity.getFlockId().toString());
            QueryWrapper<TechFlockUserEntity> oTechFlockUserQueryWrapper = new QueryWrapper();
            oTechFlockUserQueryWrapper.eq("flock_id",oYxcscFlockTalkRecordEntity.getFlockId());
            List<TechFlockUserEntity> oListTechFlockUser = oTechFlockUserMapper.selectList(oTechFlockUserQueryWrapper);
            oListCustomerFlockUserEntity = new ArrayList();
            for(TechFlockUserEntity oTechFlockUserEntity : oListTechFlockUser)
            {
                CustomerFlockUserEntity oCustomerFlockUserEntity = new CustomerFlockUserEntity();
                oCustomerFlockUserEntity.setFlockId(oTechFlockUserEntity.getFlockId());
                oCustomerFlockUserEntity.setId(oTechFlockUserEntity.getId());
                oCustomerFlockUserEntity.setUserId(oTechFlockUserEntity.getUserId());
                oCustomerFlockUserEntity.setUserName(oTechFlockUserEntity.getUserName());
                oCustomerFlockUserEntity.setMobilePhone(oTechFlockUserEntity.getMobilePhone());
                oListCustomerFlockUserEntity.add(oCustomerFlockUserEntity);
            }
        }
        
      
        MqttTextInforFlockVO oMqttInforFlockVO = new MqttTextInforFlockVO();
        SenderVO oSenderVO = new SenderVO();
        oSenderVO.setUserId(oYxcscFlockTalkRecordEntity.getSenderId().toString());
        oSenderVO.setNickName(oYxcscFlockTalkRecordEntity.getSenderName());
        oMqttInforFlockVO.setRecordId(oYxcscFlockTalkRecordEntity.getId());
        oMqttInforFlockVO.setFlockId(oYxcscFlockTalkRecordEntity.getFlockId().toString());
        oMqttInforFlockVO.setContent(oYxcscFlockTalkRecordEntity.getTalkInfo());
        oMqttInforFlockVO.setContentType(oYxcscFlockTalkRecordEntity.getTalkInfoType());
        oMqttInforFlockVO.setFlockType(oYxcscFlockTalkRecordEntity.getFlockType());
        oMqttInforFlockVO.setSendTime(oYxcscFlockTalkRecordEntity.getCreateTime());
        oMqttInforFlockVO.setSender(oSenderVO);
        JSONObject oFlockJSONObject = (JSONObject)JSON.toJSON(oMqttInforFlockVO);
        oMqttGateway.sendToMqtt(topicFlock, oFlockJSONObject.toString());
        ErrorLog.Log("客服发送群聊天信息到群后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------msgId:" + oYxcscFlockTalkRecordEntity.getId());
        ErrorLog.Log("topicFlock:" + topicFlock);
        ErrorLog.Log("oFlockJSONObject:" + oFlockJSONObject.toString());  
        //System.out.println("客服发送聊天信息到群后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------");
        //System.out.println("topic:" + topicFlock);
        //System.out.print("oJSONObject:" + oFlockJSONObject.toString());
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.GROUP_CHAT_MESSAGES);
        if(null == oYxCsNoticeEntity)
        {
            System.out.println(NoticeTypeEnum.GROUP_CHAT_MESSAGES.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_CHAT_MESSAGES.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException(NoticeTypeEnum.GROUP_CHAT_MESSAGES.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_CHAT_MESSAGES.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            return BaseResult.failed(NoticeTypeEnum.GROUP_CHAT_MESSAGES.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_CHAT_MESSAGES.getCodeType()+"找不到通知配置参数,系统通知发送失败");
        }
        String msg = oYxCsNoticeEntity.getNoticeDec();
        List<MemberVo> list = new ArrayList();
        for(CustomerFlockUserEntity oCustomerFlockUserEntity : oListCustomerFlockUserEntity)
        {
            MemberVo oMemberVo = new MemberVo();
            oMemberVo.setId(oCustomerFlockUserEntity.getUserId());
            oMemberVo.setUserName(oCustomerFlockUserEntity.getUserName());
            oMemberVo.setPhone(oCustomerFlockUserEntity.getMobilePhone());
            list.add(oMemberVo);
        }
        //发送群聊天通知
        if(oYxCsNoticeEntity.getStatus() == 1)
        {

            SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
            oSendNoticeViewDTO.setBussId(oYxcscFlockTalkRecordEntity.getId().toString());
            oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendNoticeViewDTO.setContentType("text");
            oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendNoticeViewDTO.setUserList(list);
            oSendNoticeViewDTO.setType(NoticeTypeEnum.GROUP_CHAT_MESSAGES);
            oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO); 
            JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
            ErrorLog.Log("发送群聊天通知完成:" + oJSONObjectxx.toString()); 
        }           
        return BaseResult.success();

    }
    /*** 
    * 客服将某个服务指派给某个客服
    * @param sender
    * @param reciver
    * @param oYxcscClientFiledServiceEntity
    * @return BaseResult
    **/
    @Override
    public BaseResult customerSetServiceToCustomer(YxCsUserEntity sender,YxCsUserEntity reciver,YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity)
    {
        JSONObject oCTJSONObject = new JSONObject();
        oCTJSONObject.put("msgType", "sys");
        oCTJSONObject.put("systemEvnetType","customerServiceTransfer");
        oCTJSONObject.put("sessionId", oYxcscClientFiledServiceEntity.getId());
        oCTJSONObject.put("clientId", oYxcscClientFiledServiceEntity.getClientId());
        oCTJSONObject.put("clientName", oYxcscClientFiledServiceEntity.getClientName());
        oCTJSONObject.put("clientAvatar", oYxcscClientFiledServiceEntity.getClientAvatar());
        oCTJSONObject.put("accessServiceId", oYxcscClientFiledServiceEntity.getCurrentAccessId());
        JSONObject oSenderJSONObject = new JSONObject();
        oSenderJSONObject.put("userId", sender.getUserId().toString());
        oSenderJSONObject.put("nickName", sender.getUserName());
        oCTJSONObject.put("sender", oSenderJSONObject);
        oCTJSONObject.put("recv", reciver.getUserId().toString());
        oCTJSONObject.put("sendTime",System.currentTimeMillis());
        String customerServiceTransferTopic = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(reciver.getUserId().toString());
        oMqttGateway.sendToMqtt(customerServiceTransferTopic, oCTJSONObject.toString());  
        ErrorLog.Log("客服Id:"+sender.getUserId()+ "Name:" + sender.getUserName()+"将服务"+oYxcscClientFiledServiceEntity.getId()+"指派给客服Id:" +reciver.getUserId()+ "Name:" + reciver.getUserName()+"客服后完成系统消息发送----------------------------------------------------------------------------------------------------------------------------recordId:");
        ErrorLog.Log("customerServiceTransferTopic:" + customerServiceTransferTopic);
        ErrorLog.Log("oCTJSONObject:" + oCTJSONObject.toString()); 
        System.out.println("客服Id:"+sender.getUserId()+ "Name:" + sender.getUserName()+"将服务"+oYxcscClientFiledServiceEntity.getId()+"指派给客服Id:" +reciver.getUserId()+ "Name:" + reciver.getUserName()+"客服后完成系统消息发送----------------------------------------------------------------------------------------------------------------------------recordId:");
        System.out.println("customerServiceTransferTopic:" + customerServiceTransferTopic);
        System.out.println("oCTJSONObject:" + oCTJSONObject.toString()); 
        YxcscServiceTalkRecordEntity oYxcscServiceTalkRecordEntity = new YxcscServiceTalkRecordEntity();
        oYxcscServiceTalkRecordEntity.setTalkInfo("您好，" + reciver.getUserName() + "将继续为您服务");
        oYxcscServiceTalkRecordEntity.setTalkInfoType(ContentTypeEnum.MULTITYPE.getCode());
        sendTalkMsgByCustomer(oYxcscClientFiledServiceEntity,oYxcscServiceTalkRecordEntity);
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.CUSTOMER_TRANSFER);
        if(null == oYxCsNoticeEntity)
        {
            //System.out.println("WORKFLOW_STATE_CHANGE 找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException("WORKFLOW_STATE_CHANGE  找不到通知配置参数,系统通知发送失败");
            System.out.println(NoticeTypeEnum.CUSTOMER_TRANSFER.getTemplateName() + "_CUSTOMER_TRANSFER_"+NoticeTypeEnum.CUSTOMER_TRANSFER.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException(NoticeTypeEnum.TESTIMONIALS.getTemplateName() + "_TESTIMONIALS_"+NoticeTypeEnum.TESTIMONIALS.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            ErrorLog.Log("客服将某个服务指派给某个客服:" + NoticeTypeEnum.CUSTOMER_TRANSFER.getTemplateName() + "_CUSTOMER_TRANSFER_"+NoticeTypeEnum.CUSTOMER_TRANSFER.getCodeType()+"找不到通知配置参数,系统通知发送失败"); 
            return BaseResult.failed(NoticeTypeEnum.CUSTOMER_TRANSFER.getTemplateName() + "_CUSTOMER_TRANSFER_"+NoticeTypeEnum.CUSTOMER_TRANSFER.getCodeType()+"找不到通知配置参数,系统通知发送失败");
        } 
        
        List<MemberVo> list = new ArrayList();
        MemberVo oMemberVo = new MemberVo();
        oMemberVo.setId(oYxcscClientFiledServiceEntity.getCoustId());
        oMemberVo.setUserName(oYxcscClientFiledServiceEntity.getCoustName());
        oMemberVo.setPhone(oYxcscClientFiledServiceEntity.getCoustMobilePhone());
        list.add(oMemberVo);        
        //客服将某个服务指派给某个客服
        if(oYxCsNoticeEntity.getStatus() == 1)
        {

            SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
            oSendNoticeViewDTO.setBussId(oYxcscClientFiledServiceEntity.getId());
            oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendNoticeViewDTO.setContentType("text");
            oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendNoticeViewDTO.setUserList(list);
            oSendNoticeViewDTO.setType(NoticeTypeEnum.CUSTOMER_TRANSFER);
            oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO); 
            JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
            ErrorLog.Log("客服将某个服务指派给某个客服:" + oJSONObjectxx.toString()); 
        }
        return BaseResult.success();

    }
    /*** 
    * 客服申请技术组协助
    * @param oYxcscClientFiledServiceEntity
    * @param oYxCsWorkflowEntity
    * @param oListTechFlockUserEntity
    * @return BaseResult
    **/
    @Override
    public BaseResult customerSetWorkflowToTechnicalSupportFlock(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,YxCsWorkflowEntity oYxCsWorkflowEntity,YxcscFlockTalkRecordEntity oYxcscFlockTalkRecordEntity,List<TechFlockUserEntity> oListTechFlockUserEntity)
    {      
        if(!oListTechFlockUserEntity.isEmpty())
        {
            //String flockId = oListTechFlockUserEntity.get(0).getFlockId().toString();
            //String topicFlock = MqttPrefixConstant.SYSTEM_TECHFLOCK_MQTT_TOPIC_PREFIX.concat(flockId);
            YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.GROUP_SWITCH);
         

            //发送群聊天记录
            sendFlockTalkMsgByCustomer(oYxcscFlockTalkRecordEntity);
            
            
            //发送工单通知
            List<MemberVo> list = new ArrayList();
            for(TechFlockUserEntity oTechFlockUserEntity : oListTechFlockUserEntity)
            {
                MemberVo oMemberVo = new MemberVo();
                oMemberVo.setId(oTechFlockUserEntity.getUserId());
                oMemberVo.setUserName(oTechFlockUserEntity.getUserName());
                oMemberVo.setPhone(oTechFlockUserEntity.getMobilePhone());
                list.add(oMemberVo);
            }
            if(null == oYxCsNoticeEntity)
            {
                //System.out.println("GROUP_SWITCH   找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
                //throw new BaseException("GROUP_SWITCH  找不到通知配置参数,系统通知发送失败");
                System.out.println(NoticeTypeEnum.GROUP_SWITCH.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_SWITCH.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
                //throw new BaseException(NoticeTypeEnum.GROUP_SWITCH.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_SWITCH.getCodeType()+"找不到通知配置参数,系统通知发送失败");  
                ErrorLog.Log("客服申请技术组协助:" + NoticeTypeEnum.GROUP_SWITCH.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_SWITCH.getCodeType()+"找不到通知配置参数,系统通知发送失败"); 
                return BaseResult.failed(NoticeTypeEnum.GROUP_SWITCH.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.GROUP_SWITCH.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            }
            if(oYxCsNoticeEntity.getStatus() == 1)
            {
                SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
                oSendNoticeViewDTO.setBussId(oYxCsWorkflowEntity.getId().toString());
                oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
                oSendNoticeViewDTO.setContentType("text");
                oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
                oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
                oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
                oSendNoticeViewDTO.setUserList(list);
                oSendNoticeViewDTO.setType(NoticeTypeEnum.GROUP_SWITCH);
                oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO);   
                JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
                ErrorLog.Log("客服申请技术组协助_发送工单通知:" + oJSONObjectxx.toString()); 
            }

            //发送3分钟无处理延时消息
            if(oYxCsNoticeEntity.getStatus() == 1)
            {
                String topicFlock = MqttPrefixConstant.THREE_POINTS_UNTREATED_TOPIC_PRODUCT;
                SendDelayNoticeDTO oSendDelayNoticeDTO = new SendDelayNoticeDTO();
                oSendDelayNoticeDTO.setBussId(oYxCsWorkflowEntity.getId().toString());
                oSendDelayNoticeDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
                oSendDelayNoticeDTO.setContentType("text");
                oSendDelayNoticeDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
                oSendDelayNoticeDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
                oSendDelayNoticeDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
                oSendDelayNoticeDTO.setUserList(list);
                oSendDelayNoticeDTO.setType(NoticeTypeEnum.GROUP_SWITCH);
                JSONObject oJSONObject = (JSONObject)JSON.toJSON(oSendDelayNoticeDTO);
                oMqttGateway.sendToMqtt(topicFlock, oJSONObject.toString());
                ErrorLog.Log("客服申请技术组协助_发送3分钟无处理延时消息:" + oJSONObject.toString()); 
            }

        }
        else
        {
            ErrorLog.Log("客服申请技术组协助:该群还没有成员，WorkflowEntityId:" + oYxCsWorkflowEntity.getId() + "sessionId:" + oYxcscClientFiledServiceEntity.getId()); 
            return BaseResult.failed("该群还没有成员");
        }     
        return BaseResult.success();
    }
    public BaseResult customerSetServiceToFlockOld(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,Long userId,List<YxCsFlockUserEntity> oListYxCsFlockUserEntity)
    {      
        if(!oListYxCsFlockUserEntity.isEmpty())
        {
            String msg = null;
            YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.GROUP_SWITCH);
            if(null != oYxCsNoticeEntity)
            {
                msg = oYxcscClientFiledServiceEntity.getClientName().concat(oYxCsNoticeEntity.getNoticeDec());
            }
            else
            {
                msg = oYxcscClientFiledServiceEntity.getClientName().concat("来消息了");
            }            
            for(YxCsFlockUserEntity oYxCsFlockUserEntity : oListYxCsFlockUserEntity)
            {
                //发送客户申请相关的客服，客户申请，客服队列
                MqttInforSystemVO oMqttInforSystemVO = new MqttInforSystemVO();
                oMqttInforSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
                oMqttInforSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
                oMqttInforSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
                oMqttInforSystemVO.setSessionId(oYxcscClientFiledServiceEntity.getId());
                oMqttInforSystemVO.setRecv(oYxCsFlockUserEntity.getUserId().toString());
                oMqttInforSystemVO.setMsgType("sys");                
                oMqttInforSystemVO.setContentType("text");
                oMqttInforSystemVO.setNotificationType("text");
                MqttSystemEventContenVO oMqttSysContenVO = new MqttSystemEventContenVO();
                BeanUtil.copyProperties(oYxcscClientFiledServiceEntity, oMqttSysContenVO);
                oMqttInforSystemVO.setContent(oMqttSysContenVO);
                String topic = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(oYxCsFlockUserEntity.getUserId().toString());
                JSONObject oJSONObject = (JSONObject)JSON.toJSON(oMqttInforSystemVO);
                oMqttGateway.sendToMqtt(topic, oJSONObject.toString());
                System.out.println("客服将某个服务指派给某个群后,成员"+oYxCsFlockUserEntity.getUserId().toString()+"完成邀请服务消息通知----------------------------------------------------------------------------------------------------------------------------");
                System.out.println("topic:" + topic);
                System.out.println("JSONObject:");
                System.out.print(oJSONObject.toString());                  
                //发送客户申请相关的客服，文本和声音通知
                YxCsUserWorkEntity oYxCsUserWorkEntity = oUserWorkService.getUserWorkGlobPara(oYxCsFlockUserEntity.getUserId());

                MqttObjectSystemVO oMqttObjectSystemVO = null;
                if(null != oYxCsUserWorkEntity){
                    if(oYxCsUserWorkEntity.getOneBoxType().toString().equals("1"))
                    {
                        oMqttObjectSystemVO = new MqttObjectSystemVO();
                        oMqttObjectSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
                        oMqttObjectSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
                        oMqttObjectSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
                        oMqttObjectSystemVO.setRecv(oYxCsFlockUserEntity.getUserId().toString());
                        oMqttObjectSystemVO.setMsgType("notification");                
                        oMqttObjectSystemVO.setContentType("text");

                        oMqttObjectSystemVO.setContent(msg);
                        topic = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(oYxCsFlockUserEntity.getUserId().toString());
                        oJSONObject = (JSONObject)JSON.toJSON(oMqttObjectSystemVO);
                        oMqttGateway.sendToMqtt(topic, oJSONObject.toString());
                        System.out.println("客服将某个服务指派给某个群后,成员"+oYxCsFlockUserEntity.getUserId().toString()+"完成文本消息通知----------------------------------------------------------------------------------------------------------------------------");
                        System.out.println("topic:" + topic);
                        System.out.println("JSONObject:");
                        System.out.print(oJSONObject.toString());  
                    }
                    if(oYxCsUserWorkEntity.getOneSoundType().toString().equals("1"))
                    {
                        oMqttObjectSystemVO = new MqttObjectSystemVO();
                        oMqttObjectSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
                        oMqttObjectSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
                        oMqttObjectSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
                        oMqttObjectSystemVO.setRecv(oYxCsFlockUserEntity.getUserId().toString());
                        oMqttObjectSystemVO.setMsgType("notification");                
                        oMqttObjectSystemVO.setContentType("sound");
                        //oMqttSysContenVO = new MqttSysContenVO();
                        //BeanUtil.copyProperties(oYxcscClientFiledServiceEntity, oMqttSysContenVO);
                        oMqttObjectSystemVO.setContent(msg);
                        topic = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(oYxCsFlockUserEntity.getUserId().toString());
                        oJSONObject = (JSONObject)JSON.toJSON(oMqttObjectSystemVO);
                        oMqttGateway.sendToMqtt(topic, oJSONObject.toString());
                        System.out.println("客服将某个服务指派给某个群后,成员"+oYxCsFlockUserEntity.getUserId().toString()+"完成声音消息通知----------------------------------------------------------------------------------------------------------------------------");
                        System.out.println("topic:" + topic);
                        System.out.println("JSONObject:");
                        System.out.print(oJSONObject.toString());  
                    }
                }
            }
        }
        else
        {
            BaseResult.failed("该群还没有成员");
        }     
        return BaseResult.success();
    } 
    /*** 
    * 技术支持组成员申请接受技术支持/点击接收
    * @param oYxCsWorkflowEntity
    * @return BaseResult
    **/  
    @Override
    public BaseResult technicalSupportAcceptWorkFlow(YxCsWorkflowEntity oYxCsWorkflowEntity)
    {
        String msg = null;
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.WORKFLOW_STATE_CHANGE);
        if(null == oYxCsNoticeEntity)
        {
            //System.out.println("WORKFLOW_STATE_CHANGE 找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException("WORKFLOW_STATE_CHANGE  找不到通知配置参数,系统通知发送失败");
            System.out.println(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_WORKFLOW_STATE_CHANGE_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            ErrorLog.Log(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_WORKFLOW_STATE_CHANGE_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败"); 
            return BaseResult.failed(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_WORKFLOW_STATE_CHANGE_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败");
        }
        msg = oYxCsNoticeEntity.getNoticeDec();
        List<MemberVo> list = new ArrayList();
        MemberVo oMemberVo = new MemberVo();
        oMemberVo.setId(oYxCsWorkflowEntity.getCustomId());
        oMemberVo.setUserName(oYxCsWorkflowEntity.getCustomName());
        oMemberVo.setPhone(oYxCsWorkflowEntity.getGroupName());
        list.add(oMemberVo);
        //发送工单通知
        if(oYxCsNoticeEntity.getStatus() == 1)
        {

            SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
            oSendNoticeViewDTO.setBussId(oYxCsWorkflowEntity.getId().toString());
            oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendNoticeViewDTO.setContentType("text");
            oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendNoticeViewDTO.setUserList(list);
            oSendNoticeViewDTO.setType(NoticeTypeEnum.WORKFLOW_STATE_CHANGE);
            oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO);
            JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
            ErrorLog.Log("技术支持组成员申请接受技术支持/点击接收_发送工单通知:" + oJSONObjectxx.toString()); 
        }        
        //return  technicalSupportAcceptWorkFlow(oYxCsWorkflowEntity);
        return BaseResult.success();
    }
    
    /*** 
    * 技术支持组成员完成技术支持
    * @param oTechnicalSupportFinishWorkFlowDTO
    * @return BaseResult
    **/
    @Override
    public BaseResult technicalSupportFinishWorkFlow(YxCsWorkflowEntity oYxCsWorkflowEntity,YxcscFlockTalkRecordEntity oYxcscFlockTalkRecordEntity)
    {
        //发送群聊天记录
        sendFlockTalkMsgByCustomer(oYxcscFlockTalkRecordEntity);
        //发送工单通知
        String msg = null;
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.WORKFLOW_STATE_CHANGE);
        if(null == oYxCsNoticeEntity)
        {
            //System.out.println("WORKFLOW_STATE_CHANGE 找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException("WORKFLOW_STATE_CHANGE  找不到通知配置参数,系统通知发送失败");
            System.out.println(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            ErrorLog.Log("技术支持组成员完成技术支持，WorkflowEntityId:" + oYxCsWorkflowEntity.getId() + NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败"); 
            return BaseResult.failed(NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getTemplateName() + "_GROUP_CHAT_MESSAGES_"+NoticeTypeEnum.WORKFLOW_STATE_CHANGE.getCodeType()+"找不到通知配置参数,系统通知发送失败");
        }
        msg = oYxCsNoticeEntity.getNoticeDec();
        List<MemberVo> list = new ArrayList();
        MemberVo oMemberVo = new MemberVo();
        oMemberVo.setId(oYxCsWorkflowEntity.getCustomId());
        oMemberVo.setUserName(oYxCsWorkflowEntity.getCustomName());
        oMemberVo.setPhone(oYxCsWorkflowEntity.getGroupName());
        list.add(oMemberVo);        
        if(oYxCsNoticeEntity.getStatus() == 1)
        {

            SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
            oSendNoticeViewDTO.setBussId(oYxCsWorkflowEntity.getId().toString());
            oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendNoticeViewDTO.setContentType("text");
            oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendNoticeViewDTO.setUserList(list);
            oSendNoticeViewDTO.setType(NoticeTypeEnum.WORKFLOW_STATE_CHANGE);
            oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO);
            JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
            ErrorLog.Log("技术支持组成员完成技术支持_发送工单通知:" + oJSONObjectxx.toString()); 
        }        
        //return  technicalSupportAcceptWorkFlow(oYxCsWorkflowEntity);
        return BaseResult.success();
    }
    @Override
    public BaseResult serviceScore(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity)
    {
        String msg = null;
        YxCsNoticeEntity oYxCsNoticeEntity = oICacheService.getSendMsgBySetting(NoticeTypeEnum.TESTIMONIALS);
        if(null == oYxCsNoticeEntity)
        {
            //System.out.println("WORKFLOW_STATE_CHANGE 找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException("WORKFLOW_STATE_CHANGE  找不到通知配置参数,系统通知发送失败");
            System.out.println(NoticeTypeEnum.TESTIMONIALS.getTemplateName() + "_TESTIMONIALS_"+NoticeTypeEnum.TESTIMONIALS.getCodeType()+"找不到通知配置参数,系统通知发送失败----------------------------------------------------------------------------------------------------------------------------");
            //throw new BaseException(NoticeTypeEnum.TESTIMONIALS.getTemplateName() + "_TESTIMONIALS_"+NoticeTypeEnum.TESTIMONIALS.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            ErrorLog.Log(NoticeTypeEnum.TESTIMONIALS.getTemplateName() + "_TESTIMONIALS_"+NoticeTypeEnum.TESTIMONIALS.getCodeType()+"找不到通知配置参数,系统通知发送失败");
            return BaseResult.failed(NoticeTypeEnum.TESTIMONIALS.getTemplateName() + "_TESTIMONIALS_"+NoticeTypeEnum.TESTIMONIALS.getCodeType()+"找不到通知配置参数,系统通知发送失败");
        } 
        
        List<MemberVo> list = new ArrayList();
        MemberVo oMemberVo = new MemberVo();
        oMemberVo.setId(oYxcscClientFiledServiceEntity.getCoustId());
        oMemberVo.setUserName(oYxcscClientFiledServiceEntity.getCoustName());
        oMemberVo.setPhone(oYxcscClientFiledServiceEntity.getCoustMobilePhone());
        list.add(oMemberVo);        
        //客户评分后通知客服
        if(oYxCsNoticeEntity.getStatus() == 1)
        {

            SendNoticeViewDTO oSendNoticeViewDTO = new  SendNoticeViewDTO();
            oSendNoticeViewDTO.setBussId(oYxcscClientFiledServiceEntity.getId());
            oSendNoticeViewDTO.setContent(oYxCsNoticeEntity.getNoticeDec());
            oSendNoticeViewDTO.setContentType("text");
            oSendNoticeViewDTO.setCycleFlag(oYxCsNoticeEntity.getCycleFlag());
            oSendNoticeViewDTO.setCycleFreq(oYxCsNoticeEntity.getCycleFreq());
            oSendNoticeViewDTO.setCycleTime(oYxCsNoticeEntity.getCycleTime());
            oSendNoticeViewDTO.setUserList(list);
            oSendNoticeViewDTO.setType(NoticeTypeEnum.WORKFLOW_STATE_CHANGE);
            oNoticeServiceImpl.sendNoticeToView(oSendNoticeViewDTO);
            JSONObject oJSONObjectxx = (JSONObject)JSON.toJSON(oSendNoticeViewDTO);
            ErrorLog.Log("技术支持组成员完成技术支持_发送工单通知:" + oJSONObjectxx.toString());
        }
        return BaseResult.success();
    }

    /*** 
    *客服撤回聊天记录
    * @param recordId 聊天记录Id
    * @param sssionId 会话Id
    * @return BaseResult
    **/
    @Override
    public BaseResult customerRevokeServiceTalkRecord(Long recordId,String sssionId)
    {
        String topicClient = MqttPrefixConstant.SYSTEM_CLIENT_MQTT_TOPIC_PREFIX.concat(sssionId);
        JSONObject oJSONObject = new JSONObject();   
        oJSONObject.put("msgType","sys");
        oJSONObject.put("systemEvnetType","customerRevokeServiceTalkRecord");
        oJSONObject.put("recordId",recordId.toString());
        oMqttGateway.sendToMqtt(topicClient, oJSONObject.toString());
        ErrorLog.Log("客服撤回聊天记录后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------recordId:" + recordId);
        ErrorLog.Log("topicClient:" + topicClient);
        ErrorLog.Log("oJSONObject:" + oJSONObject.toString());          
        return BaseResult.success();
    }
    /*** 
    *客户撤回聊天记录
    * @param recordId 聊天记录Id
    * @param sssionId 会话Id
    * @return BaseResult
    **/
    @Override
    public BaseResult clientRevokeServiceTalkRecord(Long recordId,Long customerId)
    {
        String topicClient = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(customerId.toString());
        JSONObject oJSONObject = new JSONObject();   
        oJSONObject.put("msgType","sys");
        oJSONObject.put("systemEvnetType","clientRevokeServiceTalkRecord");
        oJSONObject.put("recordId",recordId.toString());
        oMqttGateway.sendToMqtt(topicClient, oJSONObject.toString());
        ErrorLog.Log("客户撤回聊天记录后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------recordId:" + recordId);
        ErrorLog.Log("topicClient:" + topicClient);
        ErrorLog.Log("oJSONObject:" + oJSONObject.toString());          
        return BaseResult.success();
    }    
    
    /*** 
    *系统用户撤回群聊天记录
    * @param recordId 聊天记录Id
    * @param flockId 群Id
    * @param flockType 群类别:0正常分流规则的群,1技术支持组
    * @param list 群成员列表
    * @return BaseResult
    **/
    @Override
    public BaseResult userRevokeFlockTalkRecord(Long recordId, Long flockId,Integer flockType,List<MemberVo> list)
    {
        for(MemberVo oMemberVo : list)
        {
            String topic = MqttPrefixConstant.SYSTEM_SYSTEM_MQTT_TOPIC_PREFIX.concat(oMemberVo.getId().toString());
            JSONObject oJSONObject = new JSONObject();   
            oJSONObject.put("msgType","sys");
            oJSONObject.put("systemEvnetType","userRevokeFlockTalkRecord");
            oJSONObject.put("recordId",recordId.toString());
            oJSONObject.put("flockId",flockId.toString());
            oJSONObject.put("flockType",flockType.toString());
            oMqttGateway.sendToMqtt(topic, oJSONObject.toString());
            ErrorLog.Log("系统用户撤回群聊天记录后完成MQTT消息发送----------------------------------------------------------------------------------------------------------------------------recordId:" + recordId);
            ErrorLog.Log("topic:" + topic);
            ErrorLog.Log("oJSONObject:" + oJSONObject.toString());             
        }
        return BaseResult.success(list);
    }
    private JSONObject getMqttSystemEventJson(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,String eventType,MemberVo oRecvMemberVo,String msg)
    {
        
        MqttSystemEventVO oMqttInforSystemVO = new MqttSystemEventVO();
        oMqttInforSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
        oMqttInforSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
        oMqttInforSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
        oMqttInforSystemVO.setSessionId(oYxcscClientFiledServiceEntity.getId());
        oMqttInforSystemVO.setRecv(oRecvMemberVo.getId().toString());
        oMqttInforSystemVO.setFlockId(oRecvMemberVo.getFlockId());
        oMqttInforSystemVO.setMsgType("sys");                
        oMqttInforSystemVO.setContentType("json");
        oMqttInforSystemVO.setSystemEvnetType(eventType);
        MqttSystemEventContenVO oMqttSysContenVO = new MqttSystemEventContenVO();
        BeanUtil.copyProperties(oYxcscClientFiledServiceEntity, oMqttSysContenVO);
        oMqttSysContenVO.setClientId(oYxcscClientFiledServiceEntity.getClientId());
        oMqttSysContenVO.setClientName(oYxcscClientFiledServiceEntity.getClientName());
        oMqttSysContenVO.setClientAvatar(oYxcscClientFiledServiceEntity.getClientAvatar());
        oMqttSysContenVO.setShowMessage(msg);
        oMqttInforSystemVO.setContent(oMqttSysContenVO);
        JSONObject oJSONObject = (JSONObject)JSON.toJSON(oMqttInforSystemVO);
        return oJSONObject;
        /*
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("channelCode", oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("portCode", oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("shopId", oYxcscClientFiledServiceEntity.getShopId());
        oJSONObject.put("shopId", oYxcscClientFiledServiceEntity.getShopId());
        return oJSONObject;
        */
    }
}
